package com.jaydenxiao.common.basebean;

import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.os.Parcel;
import android.os.Parcelable;

import com.jaydenxiao.common.BR;
import com.jaydenxiao.common.base.IBaseMulInterface;

import java.util.ArrayList;

/**
 * Created by hasee on 2017/10/24.
 */

public class ItemBean extends BaseObservable implements Parcelable,IBaseMulInterface {


    private String key;
    private String value;
    private String value2;
    private String hint;
    private boolean isLabel;
    private int position;
    private int viewType;
    private String[] switchBtText;
    private ArrayList<String> imgUrlList;
    private String value3;
    private String value4;
    private int value5;//新增图片
    private int value6;
    private String errorHint;
    private boolean enable;

    protected ItemBean(Parcel in) {
        key = in.readString();
        value = in.readString();
        value2 = in.readString();
        hint = in.readString();
        isLabel = in.readByte() != 0;
        position = in.readInt();
        viewType = in.readInt();
        switchBtText = in.createStringArray();
        imgUrlList=in.createStringArrayList();
        value3 =in.readString();
        value4 =in.readString();
        value5 =in.readInt();
        value6 =in.readInt();
        errorHint=in.readString();
        enable=in.readByte() != 0;
    }

    public static final Creator<ItemBean> CREATOR = new Creator<ItemBean>() {
        @Override
        public ItemBean createFromParcel(Parcel in) {
            return new ItemBean(in);
        }

        @Override
        public ItemBean[] newArray(int size) {
            return new ItemBean[size];
        }
    };

    public String getKey() {
        if (key == null)
            key = "";
        return key;
    }

    @Bindable
    public String getValue() {
        if (value == null)
            value = "";
        return value;
    }

    public String getValue2() {
        if (value2 == null)
            value2 = "";
        return value2;
    }

    public String getValue3() {
        if (value3 == null)
            value3 = "";
        return value3;
    }

    public String getErrorHint() {
        if (errorHint == null)
            errorHint = "";
        return errorHint;
    }

    public int getValue5() {
        return value5;
    }

    public int getValue6() {
        return value6;
    }

    public void setErrorHint(String errorHint) {
        this.errorHint = errorHint;
    }

    public boolean isEnable() {
        return enable;
    }

    public void setEnable(boolean enable) {
        this.enable = enable;
    }

    public void setValue3(String value3) {
        this.value3 = value3;
    }

    public String getValue4() {
        if (value4 == null)
            value4 = "";
        return value4;
    }

    public void setValue4(String value4) {
        this.value4 = value4;
    }

    public void setValue2(String value2) {
        this.value2 = value2;
    }

    public String getHint() {
        if (hint == null)
            hint = "";
        return hint;
    }

    public void setSwitchBtText(String[] switchBtText) {
        this.switchBtText = switchBtText;
    }

    public String[] getSwitchBtText() {
        return switchBtText;
    }

    @Bindable
    public ArrayList<String> getImgUrlList() {
        if (imgUrlList==null){
            imgUrlList=new ArrayList<String>();
        }
        return imgUrlList;
    }

    public void setValue(String value) {
        this.value = value;
        notifyPropertyChanged(BR.value);
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public void setImgUrlList(ArrayList<String> imgUrlList) {
        this.imgUrlList = imgUrlList;
        notifyPropertyChanged(BR.imgUrlList);
    }

    public boolean isLabel() {
        return isLabel;
    }


    public int getViewType() {
        return viewType;
    }

    public int getPosition() {
        return position;
    }

    public ItemBean(Builder builder) {
        this.key=builder.key;
        this.hint=builder.hint;
        this.value=builder.value;
        this.value2=builder.value2;
        this.isLabel=builder.isLabel;
        this.position=builder.position;
        this.viewType=builder.viewType;
        this.switchBtText=builder.switchBtText;
        this.imgUrlList=builder.imgUrlList;
        this.value3 =builder.value3;
        this.value4 =builder.value4;
        this.value5 =builder.value5;
        this.value6 =builder.value6;
    }

    public void setLabel(boolean label) {
        isLabel = label;
    }

    @Override
    public int getItemLayoutId() {
        return viewType;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(key);
        dest.writeString(value);
        dest.writeString(value2);
        dest.writeString(hint);
        dest.writeByte((byte) (isLabel ? 1 : 0));
        dest.writeInt(position);
        dest.writeInt(viewType);
        dest.writeInt(value5);
        dest.writeInt(value6);
        dest.writeStringArray(switchBtText);
        dest.writeStringList(imgUrlList);
        dest.writeString(value3);
        dest.writeString(value4);
        dest.writeString(errorHint);
        dest.writeByte((byte) (enable ? 1 : 0));
    }

    public static class Builder{
        private String key;
        private String value;
        private String value2;
        private String hint;
        private boolean isLabel;
        private int position;
        private int viewType;
        private String[] switchBtText;
        private ArrayList<String> imgUrlList;
        private String value3;
        private String value4;
        private int value5;
        private int value6;
        private String errorHint;
        private boolean enable;

        public Builder key(String key) {
            this.key = key;
            return this;
        }

        public Builder value(String value) {
            this.value = value;
            return this;
        }

        public Builder value2(String value2) {
            this.value2 = value2;
            return this;
        }

        public Builder hint(String hint) {
            this.hint = hint;
            return this;
        }

        public Builder errorHint(String errorHint) {
            this.errorHint = errorHint;
            return this;
        }

        public Builder enable(boolean enable) {
            this.enable = enable;
            return this;
        }

        public Builder value3(String value3) {
            this.value3 = value3;
            return this;
        }

        public Builder value4(String value4) {
            this.value4 = value4;
            return this;
        }

        public Builder value5(int value5) {
            this.value5 = value5;
            return this;
        }

        public Builder value6(int value6) {
            this.value6 = value6;
            return this;
        }

        public Builder isLabel(boolean isLabel) {
            this.isLabel = isLabel;
            return this;
        }

        public Builder position(int position) {
            this.position = position;
            return this;
        }
        public Builder viewType(int viewType) {
            this.viewType = viewType;
            return this;
        }
        public Builder switchBtText(String[] switchBtText) {
            this.switchBtText = switchBtText;
            return this;
        }

        public Builder imgUrlList(ArrayList<String> imgUrlList) {
            this.imgUrlList = imgUrlList;
            return this;
        }

        public ItemBean build(){
            return new ItemBean(this);
        }


    }





}
